//
// Created by 王一飞 on 2021/4/10.
//

#ifndef HEALTH_SERVER_THREAD_POOL_H
#define HEALTH_SERVER_THREAD_POOL_H

typedef struct threadpool_server_
{
    pthread_mutex_t lock;           /* 锁住整个结构体 */
    pthread_mutex_t thread_counter; /* 用于使用忙线程数时的锁 */
    pthread_cond_t queue_not_full;  /* 条件变量，任务队列不为满 */
    pthread_cond_t queue_not_empty; /* 任务队列不为空 */

    pthread_t *threads;            /* 存放线程的tid,实际上就是管理了线数组 */
    pthread_t admin_tid;           /* 管理者线程tid */
    pthread_t message_tid;

    /*线程池信息*/
    int min_thr_num;       /* 线程池中最小线程数 */
    int max_thr_num;       /* 线程池中最大线程数 */
    int live_thr_num;      /* 线程池中存活的线程数 */
    int busy_thr_num;      /* 忙线程，正在工作的线程 */
    int wait_exit_thr_num; /* 需要销毁的线程数 */

    /*rabbitmq信息*/
    unsigned int messCnt;


    /* 存在的任务数 */
    int queue_max_size; /* 队列能容纳的最大任务数 */
    /*线程池状态*/
    int shutdown; /* true为关闭 */
} threadpool_server;

// 创建线程池
/**
 *
 * @param min_thr_num
 * @param max_thr_num
 * @param conn
 * @return
 */
threadpool_server *threadpool_create(int min_thr_num, int max_thr_num);
int threadpool_free(threadpool_server *pool);
int getSelfChannel(threadpool_server *threadpool);
void *threadpool_thread(void *threadpool);
void *admin_thread(void *threadpool);


_Noreturn void *rabbitmq_thread(void *threadpool);

#endif //HEALTH_SERVER_THREAD_POOL_H
